package ch10;

import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JTextArea;


/**
 * 
 *                       
 * @Filename ResourceTest.java
 *
 * @Description test 《cj》 page 499
 *
 * @Version 1.0
 *
 * @Author yshaohao
 *
 * @Email yshaohao@yiji.com
 *       
 * @History
 *<li>Author: yshaohao</li>
 *<li>Date: 2013-5-12</li>
 *<li>Version: 1.0</li>
 *<li>Content: create</li>
 *
 */
public class ResourceTest {
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				ResourceTestFrame frame = new ResourceTestFrame();
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setVisible(true);
			}
		});
	}
}

class ResourceTestFrame extends JFrame {
	
	public ResourceTestFrame() {
		setTitle("ResourceTest");
		setSize(DEFAULT_HEIGHT, DEFAULT_HEIGHT);
		//for image or radio, use getResource()
		URL aboutUrl = getClass().getResource("about.gif");
		Image image = Toolkit.getDefaultToolkit().getImage(aboutUrl);
		setIconImage(image);
		
		JTextArea textArea = new JTextArea();
		InputStream inputStream = getClass().getResourceAsStream("about.txt");
		Scanner in = new Scanner(inputStream);
		while (in.hasNext()) {
			textArea.append(in.nextLine() + "\n");
		}
		add(textArea);
	}
	
	public static final int DEFAULT_WIDTH = 300;
	public static final int DEFAULT_HEIGHT = 300;
}
